package com.baozou.app.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;

import com.baozou.app.view.DragImageView;

public class PagerAdapterDemo extends PagerAdapter {
	
	private final static String D = "PagerAdapterDemo";

	DragImageView[] ivs;
	
	public PagerAdapterDemo(DragImageView[] ivs){
		this.ivs = ivs;
	}
	
	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}
	
	@Override
	public int getCount() {
		return ivs.length;
	}
	
	@Override
	public Object instantiateItem(View container, int position) {
		Log.d(D, "instantiateItem:"+position);
		((ViewPager)container).addView(ivs[position], position);
		return ivs[position];
	}
	
	@Override
	public void destroyItem(View container, int position, Object object) {
		Log.d(D, "destroyItem:"+position);
		((ViewPager)container).removeView(ivs[position]);
	}

	public DragImageView getItem(int position){
		return ivs[position];
	}
}
